﻿#region 引用命名空间
using System;
using System.Configuration;
using System.Data;
#region 自定义命名空间
using System.Reflection;
using System.Text;
using System.Xml;
using System.Drawing;
using System.Net;
using System.Data.SqlTypes;
using System.IO;
using System.Linq;
using System.Drawing.Imaging;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections;

using System.Web.UI;
using System.Web.UI.WebControls;
using HttpContext = System.Web.HttpContext;

#endregion
#endregion

namespace GPCSC.Webs
{
    public class Usual : PageBase
    {
        #region 静态变量和属性

        public static string m_value
        {
            get
            {
                return "TheFallAngel";
            }
        }

        #endregion

        public Usual()
        {

        }

        #region 静态函数

        #region ProtoBuf and WCF restful

        #endregion

        #region Session,QueryString,ViewState转换函数

        /// <summary>
        /// 返回 Request.QueryString指定名称的值
        /// </summary>
        /// <param name="QueryStringName">制定的名称</param>
        /// <returns>返回值对象 object对象</returns>
        public static object f_querystringToObj(string querystringName)
        {
            var Request = HttpContext.Current.Request;
            var qs = Request.QueryString[querystringName];
            if (qs == null)
            {
                return null;
            }
            else if (qs == "undefined")
            {
                return string.Empty;
            }
            else if (qs == string.Empty)
            {
                return string.Empty;
            }
            return qs;
        }

        /// <summary>
        /// 返回 Request.QueryString指定名称的值
        /// </summary>
        /// <param name="QueryStringName">制定的名称</param>
        /// <returns>返回值对象 string对象</returns>
        public static string f_querystringToString(string querystringName)
        {
            var Request = HttpContext.Current.Request;
            var name = Request.QueryString[querystringName];
            try
            {
                if (name == null)
                {
                    return string.Empty;
                }
                else if (name == string.Empty)
                {
                    return string.Empty;
                }
                else if (name == "undefined")
                {
                    return string.Empty;
                }
                return name.Trim();
            }
            catch
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// 返回 Request.QueryString指定名称的值
        /// </summary>
        /// <param name="QueryStringName">制定的名称</param>
        /// <returns>返回值对象 decimal对象</returns>
        public static decimal f_querystringToDecimal(string querystringName)
        {
            var Request = HttpContext.Current.Request;
            var name = Request.QueryString[querystringName];
            if (name == null)
            {
                return 0;
            }
            else if (name == string.Empty)
            {
                return 0;
            }
            try
            {
                return Convert.ToDecimal(name);
            }
            catch
            {
                return 0;
            }

        }

        /// <summary>
        /// 返回 Request.QueryString指定名称的值
        /// </summary>
        /// <param name="QueryStringName">制定的名称</param>
        /// <returns>返回值对象 string大写对象</returns>
        public static string f_querystringToUpperString(string querystringName)
        {
            var Request = HttpContext.Current.Request;
            var name = Request.QueryString[querystringName];
            if (name == null)
            {
                return string.Empty;
            }
            else if (name == string.Empty)
            {
                return string.Empty;
            }
            else if (name == "undefined")
            {
                return string.Empty;
            }
            return name.Trim().ToUpper();
        }

        /// <summary>
        /// 返回 Request.QueryString指定名称的值
        /// </summary>
        /// <param name="QueryStringName">制定的名称</param>
        /// <returns>返回值对象 object对象</returns>
        public static object f_requestParamsToObj(string querystringName)
        {
            var Request = HttpContext.Current.Request;
            var name = Request.Params[querystringName];
            if (name == null)
            {
                return null;
            }
            else if (name == "undefined")
            {
                return string.Empty;
            }
            else if (name == string.Empty)
            {
                return string.Empty;
            }
            return name;
        }

        /// <summary>
        /// 返回 Request.QueryString指定名称的值
        /// </summary>
        /// <param name="QueryStringName">制定的名称</param>
        /// <returns>返回值对象 string对象</returns>
        public static string f_requestParamsToString(string querystringName)
        {
            var Request = HttpContext.Current.Request;
            var name = Request.Params[querystringName];
            if (name == null)
            {
                return string.Empty;
            }
            else if (name == "undefined")
            {
                return string.Empty;
            }
            else if (name == string.Empty)
            {
                return string.Empty;
            }
            return name.Trim();
        }

        /// <summary>
        /// 返回 Request.QueryString指定名称的值
        /// </summary>
        /// <param name="QueryStringName">制定的名称</param>
        /// <returns>返回值对象 decimal对象</returns>
        public static decimal f_requestParamsToDecimal(string querystringName)
        {
            var Request = HttpContext.Current.Request;
            var name = Request.Params[querystringName];
            if (name == null)
            {
                return 0;
            }
            else if (name == "undefined")
            {
                return 0;
            }
            else if (name == string.Empty)
            {
                return 0;
            }
            try
            {
                return Convert.ToDecimal(name);
            }
            catch
            {
                return 0;
            }

        }

        /// <summary>
        /// 返回 Request.QueryString指定名称的值
        /// </summary>
        /// <param name="QueryStringName">制定的名称</param>
        /// <returns>返回值对象 decimal对象</returns>
        public static int f_requestParamsToInt(string querystringName)
        {
            var Request = HttpContext.Current.Request;
            var name = Request.Params[querystringName];
            if (name == null)
            {
                return 0;
            }
            else if (name == "undefined")
            {
                return 0;
            }
            else if (name == string.Empty)
            {
                return 0;
            }
            try
            {
                return Convert.ToInt32(name);
            }
            catch
            {
                return 0;
            }

        }

        /// <summary>
        /// 返回 Request.QueryString指定名称的值
        /// </summary>
        /// <param name="QueryStringName">制定的名称</param>
        /// <returns>返回值对象 string大写对象</returns>
        public static string f_requestParamsToUpperString(string querystringName)
        {
            var Request = HttpContext.Current.Request;
            var name = Request.Params[querystringName];
            if (name == null)
            {
                return string.Empty;
            }
            else if (name == "undefined")
            {
                return string.Empty;
            }
            else if (name == string.Empty)
            {
                return string.Empty;
            }
            return name.Trim().ToUpper();
        }


        /// <summary>
        /// 返回 Session指定名称的值
        /// </summary>
        /// <param name="sessionName">指定的名称</param>
        /// <returns>返回值对象 object对象</returns>
        public static object f_sessionToObj(string sessionName)
        {
            var Session = HttpContext.Current.Session;
            var obj = Session[sessionName];
            if (obj == null)
            {
                return null;
            }
            else if (obj.ToString() == string.Empty)
            {
                return string.Empty;
            }
            return obj;
        }

        /// <summary>
        /// 返回 Session指定名称的值
        /// </summary>
        /// <param name="sessionName">指定的名称</param>
        /// <returns>返回值对象 object对象</returns>
        public static string f_sessionToObjString(string sessionName)
        {
            var Session = HttpContext.Current.Session;
            var obj = Session[sessionName];
            if (obj == null)
            {
                return string.Empty;
            }
            else if (obj.ToString() == string.Empty)
            {
                return string.Empty;
            }
            return obj.ToString().Trim();
        }

       

        #endregion

        #region 通用函数

        #region 反射函数

        /// <summary>
        /// 通过XmlNode属性，反射对象值
        /// </summary>
        /// <param name="obj">反射对象</param>
        /// <param name="node">XmlNode数据</param>
        public static void f_setObjectValue(object obj, XmlNode node)
        {
            //获取所有的属性Name
            PropertyDescriptorCollection attCollection = TypeDescriptor.GetProperties(obj);
            Type entitytype = Type.GetType(obj.GetType().AssemblyQualifiedName);
            foreach (PropertyDescriptor attDescriptor in attCollection)
            {
                try
                {
                    PropertyInfo propertyinfo = null;
                    try
                    {
                        propertyinfo = entitytype.GetProperty(attDescriptor.Name);
                    }
                    catch
                    {
                        continue;
                    }
                    for (int ii = 0; ii < node.Attributes.Count; ii++)
                    {
                        try
                        {
                            var att = node.Attributes[ii];
                            if (att.Name == attDescriptor.Name)
                            {
                                object objValue = Convert.ChangeType(att.Value, propertyinfo.PropertyType, null);
                                propertyinfo.SetValue(obj, objValue, null);
                                break;
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }
                catch
                {
                    continue;
                }
            }
        }

        /// <summary>
        /// 通过XmlNode属性，反射对象值
        /// </summary>
        /// <typeparam name="T">属性值动态类型</typeparam>
        /// <param name="obj">反射对象</param>
        /// <param name="name">属性名称</param>
        /// <param name="t">属性值</param>
        public static void f_setObjectValue<T>(object obj, string name, T t)
        {
            //获取所有的属性Name
            PropertyDescriptorCollection attCollection = TypeDescriptor.GetProperties(obj);
            Type entitytype = Type.GetType(obj.GetType().AssemblyQualifiedName);
            foreach (PropertyDescriptor attDescriptor in attCollection)
            {
                try
                {
                    PropertyInfo propertyinfo = null;
                    try
                    {
                        propertyinfo = entitytype.GetProperty(attDescriptor.Name);
                    }
                    catch
                    {
                        continue;
                    }
                    try
                    {
                        if (name == attDescriptor.Name)
                        {
                            object objValue = Convert.ChangeType(t, propertyinfo.PropertyType, null);
                            propertyinfo.SetValue(obj, objValue, null);
                            break;
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
                catch
                {
                    continue;
                }
            }
        }

        #endregion

        #region 图像处理函数

        /// <summary>
        /// Make the image transparent. 
        /// The input is the color which you want to make transparent.
        /// </summary>
        /// <param name="color">The color to make transparent.</param>
        /// <param name="bitmap">The bitmap to make transparent.</param>
        /// <returns>New memory stream containing transparent background gif.</returns>
        public Bitmap f_makeTransparentGif(Bitmap bitmap, Color color)
        {
            byte R = color.R;
            byte G = color.G;
            byte B = color.B;

            var fin = new MemoryStream();
            bitmap.Save(fin, ImageFormat.Gif);

            var fout = new MemoryStream((int)fin.Length);
            int count = 0;
            byte[] buf = new byte[256];
            byte transparentIdx = 0;
            fin.Seek(0, SeekOrigin.Begin);
            //header
            count = fin.Read(buf, 0, 13);
            if ((buf[0] != 71) || (buf[1] != 73) || (buf[2] != 70)) return null; //GIF

            fout.Write(buf, 0, 13);

            int i = 0;
            if ((buf[10] & 0x80) > 0)
            {
                i = 1 << ((buf[10] & 7) + 1) == 256 ? 256 : 0;
            }

            for (; i != 0; i--)
            {
                fin.Read(buf, 0, 3);
                if ((buf[0] == R) && (buf[1] == G) && (buf[2] == B))
                {
                    transparentIdx = (byte)(256 - i);
                }
                fout.Write(buf, 0, 3);
            }

            bool gcePresent = false;
            while (true)
            {
                fin.Read(buf, 0, 1);
                fout.Write(buf, 0, 1);
                if (buf[0] != 0x21) break;
                fin.Read(buf, 0, 1);
                fout.Write(buf, 0, 1);
                gcePresent = (buf[0] == 0xf9);
                while (true)
                {
                    fin.Read(buf, 0, 1);
                    fout.Write(buf, 0, 1);
                    if (buf[0] == 0) break;
                    count = buf[0];
                    if (fin.Read(buf, 0, count) != count) return null;
                    if (gcePresent)
                    {
                        if (count == 4)
                        {
                            buf[0] |= 0x01;
                            buf[3] = transparentIdx;
                        }
                    }
                    fout.Write(buf, 0, count);
                }
            }
            while (count > 0)
            {
                count = fin.Read(buf, 0, 1);
                fout.Write(buf, 0, 1);
            }
            fin.Close();
            fout.Flush();

            return new Bitmap(fout);
        }

        #endregion

        #region string函数

        /// <summary>
        /// 去除空白
        /// </summary>
        /// <param name="instring"></param>
        /// <returns></returns>
        public static string f_stringTrim(string instring)
        {
            var outstring = string.Empty;
            try
            {
                outstring = instring.Trim();
            }
            catch
            {
                return string.Empty;
            }
            return outstring;
        }

        /// <summary>
        /// 格式化字符串
        /// </summary>
        /// <param name="instring"></param>
        /// <returns></returns>
        public static string f_FormatString(string instring)
        {
            var sb = new StringBuilder();
            sb.Append(instring);
            sb.Replace('\n', ' ');
            sb.Replace('\r', ' ');
            sb.Replace('\t', ' ');
            sb.Replace('\"', ' ');
            return sb.ToString().Trim();
        }

        /// <summary>
        /// 格式化字符串
        /// </summary>
        /// <param name="instring"></param>
        /// <returns></returns>
        public static string f_formatString(string instring)
        {
            return f_FormatString(instring);
        }

        /// <summary>
        /// 格式化字符串为JSON可以接受的格式
        /// 替换特殊符号 \n \r \t ""等
        /// </summary>
        /// <param name="instring"></param>
        /// <returns></returns>
        public static string f_FormatStringJson(string instring)
        {
            var sb = new StringBuilder();
            sb.Append(instring);
            sb.Replace("\n", "\\n");
            sb.Replace("\r", "\\r");
            sb.Replace("\t", "\\t");
            sb.Replace("\"", "\\\"");
            return sb.ToString().Trim();
        }

        /// <summary>
        /// 格式化字符串为JSON可以接受的格式
        /// 替换特殊符号 \n \r \t ""等
        /// </summary>
        /// <param name="instring"></param>
        /// <returns></returns>
        public static string f_formatStringJson(string instring)
        {
            return f_FormatStringJson(instring);
        }

        /// <summary>
        /// 消息提示格式处理
        /// </summary>
        /// <param name="instr"></param>
        /// <returns></returns>
        public static string f_formatMessage(string instr)
        {
            var sb = new StringBuilder();
            sb.Append(instr);
            sb.Replace("\"", "\'");
            return sb.ToString();
        }

        #endregion

        #region 类型转换函数

        public static DateTime f_convertDateTime(object intimer)
        {
            try
            {
                return Convert.ToDateTime(intimer);
            }
            catch
            {
                return (DateTime)SqlDateTime.Null;
            }
        }

        public static DateTime f_nullDateTime(object intimer)
        {
            return (DateTime)SqlDateTime.Null;
        }

        public static Guid f_convertGuid(object intimer)
        {
            try
            {
                if (intimer.ToString() != "")
                {
                    Guid reguid = new Guid(intimer.ToString());
                    return reguid;
                }
                else
                {
                    return new Guid();
                }
            }
            catch
            {
                return Guid.NewGuid();
            }
        }

        public static string f_convertString(object intimer)
        {
            var str = string.Empty;
            try
            {
                str = Convert.ToString(intimer);
                if (string.IsNullOrEmpty(str))
                {
                    str = string.Empty;
                }
                if (str.ToLower() == "undefined")
                {
                    str = string.Empty;
                }
            }
            catch
            {
            }
            return str;
        }

        public static decimal f_convertDecimal(object intimer)
        {
            try
            {
                return Convert.ToDecimal(intimer);
            }
            catch
            {
                return 0;
            }
        }

        public static int f_convertInt32(object intimer)
        {
            try
            {
                return Convert.ToInt32(intimer);
            }
            catch
            {
                return 0;
            }
        }

        public static bool f_IsDecimal(object intimer)
        {
            try
            {
                Convert.ToDecimal(intimer);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 转化对象为bool类型
        /// </summary>
        /// <param name="intimer">转化对象</param>
        /// <param name="errMsg">异常消息</param>
        /// <returns>返回状态</returns>
        public static bool f_convertBool(object intimer)
        {
            try
            {
                return Convert.ToBoolean(intimer);
                //return bool.Parse(Usual.f_convertString(intimer));
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 转化对象为double类型
        /// </summary>
        /// <param name="intimer">转化对象</param>
        /// <returns>返回的double类型结果</returns>
        public static double f_convertDobule(object intimer)
        {
            try
            {
                return Convert.ToDouble(intimer);
            }
            catch
            {
                return Convert.ToDouble(0);
            }
        }

        #endregion

        #region 上传校验函数

        /// <summary>
        /// 上传文件类型检查
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static bool f_fileTypeCheck(string fileName)
        {
            string[] temptype = fileName.Split('.');
            switch (temptype[temptype.Length - 1].ToUpper())
            {
                case "EXE":
                case "COM":
                case "JS":
                    return true;
                default:
                    break;
            }
            return false;
        }

        #endregion

        #region 时间函数
       
        #endregion



        #region xml读取和对象工厂部分

        #region 获取xml对应Value

        /// <summary>
        /// 获取对应的objectFactory的xml的Value
        /// </summary>
        /// <param name="xmlPath">xml路径:"~/xx.xml"</param>
        /// <param name="Value">与默认id字段对比的值</param>
        /// <param name="AttName">属性名称</param>
        /// <returns>返回的Value</returns>
        //public static string f_getXmlValueByName(string xmlPath, string Value, string AttName)
        //{
        //    return f_getXmlValueByName(xmlPath, "item", "id", Value, AttName);
        //}

        /// <summary>
        /// 获取对应的objectFactory的xml的Value
        /// </summary>
        /// <param name="xmlPath">xml路径:"~/xx.xml"</param>
        /// <param name="xmlID">传入的可以确定唯一的一行xml的标识</param>
        /// <param name="Value">与xmlID的值</param>
        /// <param name="AttName">属性名称</param>
        /// <returns>返回的Value</returns>
        //public static string f_getXmlValueByName(string xmlPath, string xmlID, string Value, string AttName)
        //{
        //    return f_getXmlValueByName(xmlPath, "item", xmlID, Value, AttName);
        //}

        /// <summary>
        /// 获取对应的objectFactory的xml的Value
        /// </summary>
        /// <param name="xmlPath">xml路径:"~/xx.xml"</param>
        /// <param name="TagName">xml标识行名称</param>
        /// <param name="xmlID">传入的可以确定唯一的一行xml的标识</param>
        /// <param name="Value">与xmlID的值</param>
        /// <param name="AttName">属性名称</param>
        /// <returns>返回的Value</returns>
        //public static string f_getXmlValueByName(string xmlPath, string TagName, string xmlID, string Value, string AttName)
        //{
        //    var xml = new xmlBase(xmlPath);
        //    var list = xml.GetXmlNodeListWithTag(TagName);
        //    var node = xml.GetXmlNode(list, xmlID, Value);
        //    string Path = string.Empty;
        //    Path = Usual.f_getXmlNodeAttribValue(node, AttName);
        //    return Path;
        //}

        /// <summary>
        /// 获取对应的objectFactory的xml的InnerText
        /// </summary>
        /// <param name="xmlPath">xml路径:"~/xx.xml"</param>
        /// <param name="Value">与默认id字段对比的值</param>
        /// <param name="AttName">属性名称</param>
        /// <returns>返回的Value</returns>
        //public static string f_getXmlNodeInnerText(string xmlPath, string Value, string AttName)
        //{
        //    return f_getXmlNodeInnerText(xmlPath, "item", "id", Value, AttName);
        //}

        /// <summary>
        /// 获取对应的objectFactory的xml的InnerText
        /// </summary>
        /// <param name="xmlPath">xml路径:"~/xx.xml"</param>
        /// <param name="xmlID">传入的可以确定唯一的一行xml的标识</param>
        /// <param name="Value">与xmlID的值</param>
        /// <param name="AttName">属性名称</param>
        /// <returns>返回的Value</returns>
        //public static string f_getXmlNodeInnerText(string xmlPath, string xmlID, string Value, string AttName)
        //{
        //    return f_getXmlNodeInnerText(xmlPath, "item", xmlID, Value, AttName);
        //}

        /// <summary>
        /// 获取对应的objectFactory的xml的InnerText
        /// </summary>
        /// <param name="xmlPath">xml路径:"~/xx.xml"</param>
        /// <param name="TagName">xml标识行名称</param>
        /// <param name="xmlID">传入的可以确定唯一的一行xml的标识</param>
        /// <param name="Value">与xmlID的值</param>
        /// <param name="AttName">属性名称</param>
        /// <returns>返回的Value</returns>
        //public static string f_getXmlNodeInnerText(string xmlPath, string TagName, string xmlID, string Value, string AttName)
        //{
        //    var xml = new xmlBase(xmlPath);
        //    var list = xml.GetXmlNodeListWithTag(TagName);
        //    var node = xml.GetXmlNode(list, xmlID, Value);
        //    if (node == null)
        //    {
        //        return string.Empty;
        //    }
        //    return node.InnerText;
        //}

        /// <summary>
        /// 获取xml路径value,参考"~/Configuration/objectFactory/objectFactory.config"中的配置
        /// </summary>
        /// <param name="AttName">config文件中对应的属性</param>
        /// <param name="m_queryCustomerName">自定义objectPath.config中id</param>
        /// <returns></returns>
        //public string f_xmlValuePath(string AttName, string m_queryCustomerName)
        //{
        //    var Path = f_getXmlValueByName(f_returnPathByID(m_queryCustomerName), m_queryCustomerName, AttName);
        //    return Path;
        //}

        #endregion

        #region xml读写objectPath.xml

        /// <summary>
        /// 通过id,返回动态配置的xml路径
        /// </summary>
        /// <param name="m_queryName">标示一行的id或者值</param>
        /// <returns></returns>
        //public static string f_returnPathByID(string m_queryName)
        //{
        //    string path = ConfigurationManager.AppSettings["objectPath"];
        //    var xmlbase = new xmlBase(path);
        //    var pathList = xmlbase.GetXmlNodeListWithTag("path");
        //    string queryValue = m_queryName;
        //    var pathnode = xmlbase.GetXmlNode(pathList, queryValue);
        //    return Usual.f_getXmlNodeAttribValue(pathnode, "xmlPath");
        //}

        /// <summary>
        /// 通过id,返回动态配置的xml路径
        /// </summary>
        /// <param name="m_path">config文件路径</param>
        /// <param name="m_queryName">标示一行的id或者值</param>
        /// <returns></returns>
        //public static string f_returnPathByID(string m_path, string m_queryName)
        //{
        //    //string path = System.Configuration.ConfigurationManager.AppSettings["objectPath"];
        //    string path = m_path;
        //    var xmlbase = new xmlBase(path);
        //    var pathList = xmlbase.GetXmlNodeListWithTag("path");
        //    string queryValue = m_queryName;
        //    var pathnode = xmlbase.GetXmlNode(pathList, queryValue);
        //    return Usual.f_getXmlNodeAttribValue(pathnode, "xmlPath");
        //}

        #endregion

        #region 获取xml指定节点的值，如果不存在该节点，那么设置值为""
        /// <summary>
        /// 获取xml指定节点的值，如果不存在该节点，那么设置值为""
        /// </summary>
        /// <param name="node"></param>
        /// <param name="AttName"></param>
        /// <returns></returns>
        public static string f_getXmlNodeAttribValue(XmlNode node, string AttName)
        {
            string Path = string.Empty;
            if (node != null)
            {
                if (node.Attributes[AttName] != null)
                {
                    Path = node.Attributes[AttName].Value;
                }
            }
            return Path;
        }

        /// <summary>
        /// 获取xml指定节点的值，如果不存在该节点，那么设置值为""
        /// </summary>
        /// <param name="node"></param>
        /// <param name="AttName"></param>
        /// <returns></returns>
        public static object f_getXmlNodeAttribValueObj(XmlNode node, string AttName)
        {
            object Path = string.Empty;
            if (node != null)
            {
                if (node.Attributes[AttName] != null)
                {
                    Path = node.Attributes[AttName].Value;
                }
            }
            return Path;
        }
        #endregion

        #endregion

        #region 数据转换函数

        public static List<T> f_convertList<T>(T[] t)
        {
            var list = t.ToList<T>();
            return list;
        }

        #endregion

        #region 下拉菜单函数

        /// <summary>
        /// 下拉菜单函数,从字符串中分离绑定，默认字符串:是否
        /// </summary>
        /// <param name="SplitChar"></param>
        /// <param name="emptyValue"></param>
        /// <param name="SelectValue"></param>
        /// <param name="contrl"></param>
        internal static void f_ddlDataBind(string emptyValue, string SelectValue, object Objcontrl)
        {
            DropDownList control = null;
            try
            {
                control = (DropDownList)Objcontrl;
            }
            catch
            {
                return;
            }
            string Names = "是|否";
            string Values = "0|1";
            var nameStr = Names.Split('|');
            var valueStr = Values.Split('|');
            int count = nameStr.Length;
            var cls = new DropDownListClass[count];
            for (int i = 0; i < count; i++)
            {
                cls[i] = new DropDownListClass();
                cls[i].Name = nameStr[i];
                if (valueStr[i] != null)
                {
                    cls[i].Value = valueStr[i];
                }
                else
                {
                    cls[i].Value = emptyValue;
                }
            }
            control.DataTextField = "Name";
            control.DataValueField = "Value";
            control.DataSource = cls;
            control.DataBind();
            if (!string.IsNullOrEmpty(SelectValue))
            {
                control.SelectedValue = SelectValue;
            }
        }

        /// <summary>
        /// 下拉菜单函数,从字符串中分离绑定
        /// </summary>
        /// <param name="Names"></param>
        /// <param name="Values"></param>
        /// <param name="SplitChar"></param>
        /// <param name="emptyValue"></param>
        /// <param name="SelectValue"></param>
        /// <param name="contrl"></param>
        internal static void f_ddlDataBind(string Names, string Values, char SplitChar, string emptyValue, string SelectValue, DropDownList contrl)
        {
            var nameStr = Names.Split(SplitChar);
            var valueStr = Values.Split(SplitChar);
            int count = nameStr.Length;
            var cls = new DropDownListClass[count];
            for (int i = 0; i < count; i++)
            {
                cls[i] = new DropDownListClass();
                cls[i].Name = nameStr[i];
                if (valueStr[i] != null)
                {
                    cls[i].Value = valueStr[i];
                }
                else
                {
                    cls[i].Value = emptyValue;
                }
            }
            contrl.DataTextField = "Name";
            contrl.DataValueField = "Value";
            contrl.DataSource = cls;
            contrl.DataBind();
            if (!string.IsNullOrEmpty(SelectValue))
            {
                contrl.SelectedValue = SelectValue;
            }
        }

        #endregion

        #endregion

        #region 业务模块


        #region 一级函数.GreatDiary模块

        /// <summary>
        /// 获取密码加密完数据
        /// </summary>
        /// <param name="password">传入密码</param>
        /// <returns></returns>
        //public static string f_gdPasswordEncrypt(string password)
        //{
        //    var ezc = new NickLee.Crypto.ezCrypto();
        //    ezc.CharacterSet = NickLee.Crypto.CharSet.UniCode;
        //    ezc.PersistentStream = true;
        //    ezc.Key = m_value;
        //    ezc.Iv = m_value;

        //    string EncryptStr = password;

        //    ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.BlowFish;
        //    EncryptStr = ezc.Encrypt(EncryptStr);

        //    ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.RC2;
        //    EncryptStr = ezc.Encrypt(EncryptStr);

        //    ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.Rijndael;
        //    EncryptStr = ezc.Encrypt(EncryptStr);

        //    ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.TripleDES;
        //    EncryptStr = ezc.Encrypt(EncryptStr);

        //    return EncryptStr;
        //}

        /// <summary>
        /// 获取密码加密完数据库数据
        /// </summary>
        /// <param name="password">传入密码</param>
        /// <param name="iKey">Key</param>
        /// <param name="iIV">IV</param>
        /// <returns>加密完字符串</returns>
        //public static string f_gdContextEncrypt(string context, string iKey, string iIV)
        //{
        //    string EncryptStr = string.Empty;
        //    try
        //    {
        //        var ezc = new NickLee.Crypto.ezCrypto();
        //        ezc.CharacterSet = NickLee.Crypto.CharSet.UniCode;
        //        ezc.PersistentStream = true;
        //        ezc.Key = iKey;
        //        ezc.Iv = iIV;

        //        EncryptStr = context;

        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.TripleDES;
        //        EncryptStr = ezc.Encrypt(EncryptStr);

        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.RC2;
        //        EncryptStr = ezc.Encrypt(EncryptStr);

        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.BlowFish;
        //        EncryptStr = ezc.Encrypt(EncryptStr);

        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.Rijndael;
        //        EncryptStr = ezc.Encrypt(EncryptStr);
        //    }
        //    catch
        //    {
        //        return string.Empty;
        //    }
        //    return EncryptStr;
        //}

        /// <summary>
        /// 获取密码解密完数据
        /// </summary>
        /// <param name="password">传入加密密码</param>
        /// <returns></returns>
        //public static string f_gdPasswordDecrypt(string ePassword)
        //{
        //    var ezc = new NickLee.Crypto.ezCrypto();
        //    ezc.CharacterSet = NickLee.Crypto.CharSet.UniCode;
        //    ezc.PersistentStream = true;
        //    ezc.Key = m_value;
        //    ezc.Iv = m_value;

        //    string DecryptStr = ePassword;

        //    ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.TripleDES;
        //    DecryptStr = ezc.Decrypt(DecryptStr);

        //    ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.Rijndael;
        //    DecryptStr = ezc.Decrypt(DecryptStr);

        //    ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.RC2;
        //    DecryptStr = ezc.Decrypt(DecryptStr);

        //    ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.BlowFish;
        //    DecryptStr = ezc.Decrypt(DecryptStr);

        //    return DecryptStr;
        //}

        /// <summary>
        /// 获取密码解密数据
        /// </summary>
        /// <param name="password">传入加密密码</param>
        /// <param name="iKey">Key</param>
        /// <param name="iIV">IV</param>
        /// <returns>加密完字符串</returns>
        //public static string f_gdContextDecrypt(byte[] eeContext, string iKey, string iIV)
        //{
        //    var eContext = (string)NickLee.Common.CompressData.UnCompressObject(eeContext);
        //    string DecryptStr = string.Empty;
        //    try
        //    {
        //        var ezc = new NickLee.Crypto.ezCrypto();
        //        ezc.CharacterSet = NickLee.Crypto.CharSet.UniCode;
        //        ezc.PersistentStream = true;
        //        ezc.Key = iKey;
        //        ezc.Iv = iIV;

        //        DecryptStr = eContext;

        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.Rijndael;
        //        DecryptStr = ezc.Decrypt(DecryptStr);

        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.BlowFish;
        //        DecryptStr = ezc.Decrypt(DecryptStr);

        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.RC2;
        //        DecryptStr = ezc.Decrypt(DecryptStr);

        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.TripleDES;
        //        DecryptStr = ezc.Decrypt(DecryptStr);
        //    }
        //    catch
        //    {
        //        return string.Empty;
        //    }
        //    return DecryptStr;
        //}

        /// <summary>
        /// 获取真实加密解密密码Key和IV
        /// </summary>
        /// <param name="password">传入密码密文</param>
        /// <returns></returns>
        //public static void f_gdRealyPasswordKeyWithIV(byte[] ePassword, ref string sKey, ref string sIv)
        //{
        //    try
        //    {
        //        string unStr = (string)NickLee.Common.CompressData.UnCompressObject(ePassword);

        //        var ezc = new NickLee.Crypto.ezCrypto();
        //        ezc.CharacterSet = NickLee.Crypto.CharSet.UniCode;
        //        ezc.PersistentStream = true;
        //        ezc.Key = m_value;
        //        ezc.Iv = m_value;

        //        string DecryptStr = unStr;
        //        //解密一次作为Iv
        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.TripleDES;
        //        DecryptStr = ezc.Decrypt(DecryptStr);
        //        sIv = DecryptStr;
        //        //解密两次作为Key
        //        ezc.Algorithm = NickLee.Crypto.AlgorithmTypes.Rijndael;
        //        DecryptStr = ezc.Decrypt(DecryptStr);
        //        sKey = DecryptStr;
        //    }
        //    catch
        //    {
        //        return;
        //    }
        //}

        #endregion

        #region 一级函数.权限配置模块


        #endregion

        #region string 函数部分
        public static bool i_convertGuid(object intimer)
        {
            try
            {
                Guid reguid = new Guid(intimer.ToString());
                return true;
            }
            catch
            {
                return false;
            }
        }


        #endregion

        #endregion

        #region 导出数据文件函数

        /// <summary>
        /// ExcelFile导出Excel
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="sheetname"></param>
        /// <returns></returns>


        /// <summary>
        /// Aspose.Cells.WorkbookDesigner导出域模板Excel
        /// </summary>
        /// <param name="mfile"></param>
        /// <param name="dt"></param>
        /// <returns></returns>


        /// <summary>
        /// Aspose.Words.Document导出域模板Word
        /// </summary>
        /// <param name="mfile"></param>
        /// <param name="dt"></param>
        /// <returns></returns>


        /// <summary>
        /// Aspose.Words.Document导出域模板Word
        /// 打印卡片
        /// </summary>
        /// <param name="mfile"></param>
        /// <param name="dt"></param>
        /// <returns></returns>

        #endregion

        #endregion
    }
}
